#
# Copyright (C) 2000-2023 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
@MCOMMON@

# Define library versions
LIBBAC_LT_RELEASE = @LIBBAC_LT_RELEASE@
LIBBACCFG_LT_RELEASE = @LIBBACCFG_LT_RELEASE@

ZLIBS = @ZLIBS@
DEBUG = @DEBUG@
CAP_LIBS = @CAP_LIBS@
EXTRA_SRCS = @EXTRA_LIB_SRCS@

#
srcdir =	.
VPATH = 	.
.PATH:		.

# one up
basedir = ..
# top dir
topdir = ../..
# this dir relative to top dir
thisdir = src/lib

first_rule: all
dummy:

#
# include files installed when using libtool
#
INCLUDE_FILES = ../baconfig.h ../bacula.h ../bc_types.h \
      ../config.h ../jcr.h ../version.h \
      authenticatebase.h \
      address_conf.h alist.h attr.h base64.h bsockcore.h \
      berrno.h bits.h bjson.h bpipe.h breg.h bregex.h \
      bsock.h bstat.h btime.h btimers.h crypto.h dlist.h \
      flist.h fnmatch.h guid_to_name.h htable.h lex.h \
      lib.h lz4.h md5.h mem_pool.h message.h \
      openssl.h plugins.h protos.h queue.h rblist.h \
      runscript.h rwlock.h serial.h sellist.h sha1.h sha2.h \
      smartall.h status.h tls.h tree.h var.h \
      waitq.h watchdog.h workq.h \
      parse_conf.h ini.h \
      worker.h lockmgr.h devlock.h output.h bwlimit.h \
      collect.h event.h ilist.h

#
# libbac
#
LIBBAC_SRCS = attr.c base64.c base32.c berrno.c bsys.c binflate.c bget_msg.c \
      authenticatebase.cc \
      bnet.c bnet_server.c bsock.c bpipe.c bsnprintf.c bstat.c btime.c \
      cram-md5.c crypto.c daemon.c edit.c fnmatch.c \
      guid_to_name.c hmac.c jcr.c lex.c lz4.c alist.c dlist.c \
      md5.c message.c mem_pool.c openssl.c \
      plugins.c priv.c queue.c bregex.c bsockcore.c \
      runscript.c rwlock.c scan.c sellist.c serial.c sha1.c sha2.c \
      signal.c smartall.c rblist.c tls.c tree.c \
      util.c var.c watchdog.c workq.c btimers.c \
      worker.c flist.c bcollector.c collect.c \
      address_conf.c breg.c htable.c lockmgr.c devlock.c output.c bwlimit.c \
      bsock_meeting.c bcrc32.c events.c ilist.c cJSON.c cJSON_Utils.c \
      xxhash.c $(EXTRA_SRCS)

LIBBAC_OBJS_TMP = $(LIBBAC_SRCS:.c=.o)
LIBBAC_OBJS = $(LIBBAC_OBJS_TMP:.cc=.o)
LIBBAC_LOBJS_TMP = $(LIBBAC_SRCS:.c=.lo)
LIBBAC_LOBJS = $(LIBBAC_LOBJS_TMP:.cc=.lo)

#
# libbaccfg (config functions)
#
LIBBACCFG_SRCS = ini.c parse_conf.c res.c bjson.c
LIBBACCFG_OBJS = $(LIBBACCFG_SRCS:.c=.o)
LIBBACCFG_LOBJS = $(LIBBACCFG_SRCS:.c=.lo)

# libbacfind
LIBBACFINDTARGET = ../findlib/libbacfind.la

.SUFFIXES:	.c .cc .o .lo .ch .dvi .pdf .tex .view .w .1
.PHONY:
.DONTCARE:

# inference rules
.c.o:
	@echo "Compiling $<"
	$(NO_ECHO)$(DO_CHECK_DMSG) $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) -E $< | $(CHECK_DMSG)
	$(NO_ECHO)$(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<

.c.lo:
	@echo "Compiling $<"
	$(NO_ECHO)$(DO_CHECK_DMSG) $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) -E $< | $(CHECK_DMSG)
	$(NO_ECHO)$(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<

.cc.o:
	@echo "Compiling $<"
	$(NO_ECHO)$(DO_CHECK_DMSG) $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) -E $< | $(CHECK_DMSG)
	$(NO_ECHO)$(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<

.cc.lo:
	@echo "Compiling $<"
	$(NO_ECHO)$(DO_CHECK_DMSG) $(CXX) $(DEFS) $(DEBUG) -E -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< | $(CHECK_DMSG)
	$(NO_ECHO)$(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<

# specific build rules

$(LIBBACFINDTARGET):
	make -C ../findlib libbacfind.la

#-------------------------------------------------------------------------
all: Makefile libbac$(DEFAULT_ARCHIVE_TYPE) libbaccfg$(DEFAULT_ARCHIVE_TYPE)
	@echo "==== Make of lib is good ===="
	@echo " "

libbac.a: $(LIBBAC_OBJS)
	@echo "Making $@ ..."
	$(AR) rc  $@ $(LIBBAC_OBJS)
	$(RANLIB) $@

libbac.la: Makefile $(LIBBAC_LOBJS)
	@echo "Making $@ ..."
	$(LIBTOOL_LINK) $(CXX) $(DEFS) $(DEBUG) $(LDFLAGS) -o $@ $(LIBBAC_LOBJS) -export-dynamic -rpath $(libdir) -release $(LIBBAC_LT_RELEASE) $(WRAPLIBS) $(CAP_LIBS) $(ZLIBS) $(OPENSSL_LIBS) $(LIBS) $(DLLIBS)

libbaccfg.a: $(LIBBACCFG_OBJS)
	@echo "Making $@ ..."
	$(AR) rc  $@ $(LIBBACCFG_OBJS)
	$(RANLIB) $@

libbaccfg.la: Makefile $(LIBBACCFG_LOBJS)
	@echo "Making $@ ..."
	$(LIBTOOL_LINK) $(CXX) $(DEFS) $(DEBUG) $(LDFLAGS) -o $@ $(LIBBACCFG_LOBJS) -export-dynamic -rpath $(libdir) -release $(LIBBACCFG_LT_RELEASE) $(OPENSSL_LIBS) $(LIBS)

Makefile: $(srcdir)/Makefile.in $(topdir)/config.status
	cd $(topdir) \
	  && CONFIG_FILES=$(thisdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status

bsys_test: Makefile bsys.c unittests.o libbac.la $(LIBBACFINDTARGET)
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) -o bsys_test.o bsys.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -L../findlib -o $@ bsys_test.o unittests.o $(DLIB) -lbac -lbacfind -lm $(LIBS) $(OPENSSL_LIBS)

wait_test: Makefile bsys.c
	$(RMF) bsys.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bsys.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -L../findlib -o $@ bsys.o $(DLIB) -lbac -lbacfind -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/

bitmap_test: Makefile bitmap.c unittests.o bitmap.h
	$(RMF) bsys.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bitmap.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ bitmap.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/

output_test: Makefile libbac.la output.c unittests.o
	$(RMF) output.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) output.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ output.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) output.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) output.c

lockmgr_test: Makefile libbac.la lockmgr.c unittests.o
	$(RMF) lockmgr.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) lockmgr.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ lockmgr.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) lockmgr.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) lockmgr.c

base64_test: Makefile libbac.la base64.c unittests.o
	$(RMF) base64.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) base64.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ base64.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) base64.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) base64.c

base32_test: Makefile libbac.la base32.c unittests.o
	$(RMF) base32.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) base32.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ base32.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) base32.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) base32.c

edit_test: Makefile libbac.la edit.c unittests.o
	$(RMF) edit.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) edit.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ edit.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) edit.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) edit.c

flist_test: Makefile libbac.la flist.c unittests.o
	$(RMF) flist.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) flist.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ flist.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) flist.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) flist.c

fnmatch_test: Makefile libbac.la fnmatch.c unittests.o
	$(RMF) fnmatch.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) fnmatch.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ fnmatch.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) fnmatch.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) fnmatch.c

worker_test: Makefile libbac.la worker.c
	$(RMF) worker.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) worker.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ worker.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) worker.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) worker.c

workq_test: Makefile libbac.la workq.c
	$(RMF) workq.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) workq.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ workq.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) workq.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) workq.c

rwlock_test: Makefile libbac.la rwlock.c
	$(RMF) rwlock.o
	$(CXX) -DTEST_RWLOCK $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) rwlock.c
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ rwlock.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(RMF) rwlock.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) rwlock.c

devlock_test: Makefile libbac.la devlock.c
	$(RMF) devlock.o
	$(CXX) -DTEST_devlock $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) devlock.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ devlock.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) devlock.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) devlock.c

htable_test: Makefile libbac.la htable.c unittests.o
	$(RMF) htable.o
	$(CXX) -DTEST_SMALL_HTABLE -DTEST_NON_CHAR -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)	$(CFLAGS) htable.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ htable.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) htable.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) htable.c

alist_test: Makefile libbac.la alist.c unittests.o
	$(RMF) alist.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) alist.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ alist.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) alist.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) alist.c

ilist_test: Makefile libbac.la ilist.c unittests.o
	$(RMF) ilist.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) ilist.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ ilist.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) ilist.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) ilist.c

dlist_test: Makefile libbac.la dlist.c unittests.o
	$(RMF) dlist.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) dlist.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ dlist.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) dlist.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) dlist.c

crc32_test: Makefile libbac.la bcrc32.c unittests.o
	$(RMF) bcrc32.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bcrc32.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ bcrc32.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) bcrc32.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bcrc32.c

sellist_test: Makefile libbac.la sellist.c unittests.o
	$(RMF) sellist.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sellist.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ sellist.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) sellist.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sellist.c

bcrc32sum: Makefile bcrc32.o
	$(RMF) bcrc32.o
	$(CXX) -DCRC32_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) bcrc32.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ bcrc32.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(RMF) bcrc32.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bcrc32.c

xml_test: Makefile libbac.la xml.c
	$(RMF) xml.o
	$(CXX) -DTEST_PROG $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) xml.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ xml.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) xml.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) xml.c

md5sum: Makefile libbac.la md5.c
	$(RMF) md5.o
	$(CXX) -DMD5_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) md5.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ md5.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) md5.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c

sha1sum: Makefile libbac.la sha1.c
	$(RMF) sha1.o
	$(CXX) -DSHA1_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)	$(CFLAGS) sha1.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ sha1.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) sha1.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sha1.c

sha1_test: Makefile libbac.la sha1.c unittests.o
	$(RMF) sha1.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sha1.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ sha1.o unittests.o $(DLIB) -lbac -lm $(LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) sha1.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sha1.c

bsnprintf_test: Makefile libbac.la bsnprintf.c unittests.o
	$(RMF) bsnprintf.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) -Wno-format-truncation bsnprintf.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ bsnprintf.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) bsnprintf.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bsnprintf.c

ini_test: Makefile libbac.la ini.c unittests.o
	$(RMF) ini.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) ini.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ ini.o unittests.o -lbaccfg -lbac $(DLIB) -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) ini.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) ini.c

bstat_test: Makefile libbac.la bstat.c unittests.o
	$(RMF) bstat.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) bstat.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ bstat.o unittests.o $(DLIB) -lbac -lm $(LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) bstat.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bstat.c

bsock_meeting_test: Makefile libbac.la bsock_meeting.c unittests.o
	$(RMF) bsock_meeting.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) bsock_meeting.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ bsock_meeting.o unittests.o $(DLIB) -lbac -lm $(LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) bsock_meeting.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bsock_meeting.c

bsockcore_test: Makefile libbac.la bsockcore.c unittests.o
	$(RMF) bsockcore.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) bsockcore.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ bsockcore.o unittests.o $(DLIB) -lbac -lm $(LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) bsockcore.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bsockcore.c

bsock_test: Makefile libbac.la bsock.c unittests.o
	$(RMF) bsock.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) bsock.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ bsock.o unittests.o $(DLIB) -lbac -lm $(LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) bsock.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bsock.c

scan_test: Makefile libbac.la scan.c unittests.o
	$(CXX) -o scan_test.o -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) scan.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ scan_test.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/

collect_test: Makefile libbac.la collect.c unittests.o
	$(RMF) collect.o
	$(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE)  $(CFLAGS) collect.c
	$(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ collect.o unittests.o $(DLIB) -lbac -lm $(LIBS)
	$(LIBTOOL_INSTALL) $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
	$(RMF) collect.o
	$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) collect.c

install-includes:
	$(MKDIR) $(DESTDIR)/$(includedir)/bacula
	for I in $(INCLUDE_FILES); do \
	   $(INSTALL_DATA) $$I $(DESTDIR)$(includedir)/bacula/`basename $$I`; \
	done

uninstall-includes:
	for I in $(INCLUDE_FILES); do \
	   $(RMF) $(DESTDIR)$(includedir)/bacula/`basename $$I`; \
	done

libtool-install: all
	$(MKDIR) $(DESTDIR)$(libdir)
	$(RMF) $(DESTDIR)$(libdir)/libbac-*.so $(DESTDIR)$(libdir)/libbac.la
	$(RMF) $(DESTDIR)$(libdir)/libbaccfg-*.so $(DESTDIR)$(libdir)/libbaccfg.la
	$(RMF) $(DESTDIR)$(libdir)/libbacpy-*.so $(DESTDIR)$(libdir)/libbacpy.la
	$(LIBTOOL_INSTALL_FINISH) $(INSTALL_LIB) libbac.la $(DESTDIR)$(libdir)
	$(LIBTOOL_INSTALL_FINISH) $(INSTALL_LIB) libbaccfg.la $(DESTDIR)$(libdir)

libtool-uninstall:
	$(LIBTOOL_UNINSTALL) $(RMF) $(DESTDIR)$(libdir)/libbac.la
	$(LIBTOOL_UNINSTALL) $(RMF) $(DESTDIR)$(libdir)/libbaccfg.la
	$(LIBTOOL_UNINSTALL) $(RMF) $(DESTDIR)$(libdir)/libbacpy.la

install: @LIBTOOL_INSTALL_TARGET@ @INCLUDE_INSTALL_TARGET@

uninstall: @LIBTOOL_UNINSTALL_TARGET@ @INCLUDE_UNINSTALL_TARGET@

libtool-clean:
	@find . -name '*.lo' -print | xargs $(LIBTOOL_CLEAN) $(RMF)
	@$(RMF) *.la
	@$(RMF) -r .libs _libs

clean:	libtool-clean
	@$(RMF) core a.out *.o *.bak *.tex *.pdf *~ *.intpro *.extpro 1 2 3
	@$(RMF) rwlock_test md5sum sha1sum

realclean: clean
	@$(RMF) tags

distclean: realclean
	if test $(srcdir) = .; then $(MAKE) realclean; fi
	(cd $(srcdir); $(RMF) Makefile)

# Semi-automatic generation of dependencies:
# Use gcc -M because X11 `makedepend' doesn't work on all systems
# and it also includes system headers.
# `semi'-automatic since dependencies are generated at distribution time.

depend:
	@$(MV) Makefile Makefile.bak
	@$(SED) "/^# DO NOT DELETE:/,$$ d" Makefile.bak > Makefile
	@$(ECHO) "# DO NOT DELETE: nice dependency list follows" >> Makefile
	@for src in $(LIBBAC_SRCS) $(LIBBACCFG_SRCS); do \
	    $(CXX) -S -M -MT `basename $$src .c`$(DEFAULT_OBJECT_TYPE) $(CPPFLAGS) $(XINC) -I$(srcdir) -I$(basedir) $$src >> Makefile; \
	done
	@if test -f Makefile ; then \
	    $(RMF) Makefile.bak; \
	else \
	   $(MV) Makefile.bak Makefile; \
	   echo " ===== Something went wrong in make depend ====="; \
	fi

# -----------------------------------------------------------------------
# DO NOT DELETE: nice dependency list follows
